FastAPI by AUTHOR NAMES HERE
Type Hints
All of this background has a point.
Python 3.6 added type hints to declare the type of object to which a variable refers. These are not enforced by the Python interpreter as itâs running! Instead, they can be used by various tools to ensure that your use of a variable is consistent. The standard type checker is called mypy, and Iâll show you how itâs used later.
A type hint may just seem like a nice thing, like many âlintâ tools used by programmers to avoid some mistakes. For instance, it may remind you that your variable count refers to a Python object of type int. But hints, although theyâre optional and unenforced notes (literally, âhintsâ), turn out to have unexpected uses. Later in this book, youâll see how FastAPI adapted the Pydantic package to make very clever use of type hinting.
The addition of type declarations may be a trend in other, formerly typeless, languages. For example, many JavaScript developers have moved to TypeScript.